﻿using System.IO;
using System.Threading.Tasks;
using housingsafety.server.Helpers;
using housingsafety.server.Models;
using Microsoft.AspNetCore.Http;

namespace housingsafety.server.Svcs
{
    /// <summary>
    /// 文件存储
    /// </summary>
    public interface IStorageProvider
    {
        /// <summary>
        /// 提供程序名称
        /// </summary>
        string ProviderName { get; }

        /// <summary>
        /// 通过文件名删除对应的文件
        /// </summary>
        /// <param name="storePath">对象相对路径</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>是否成功</returns>
        Task<bool> DeleteObjectByNameAsync(FilePath storePath, string userName, string groupName);

        /// <summary>
        /// 获取网关连接
        /// </summary>
        /// <param name="context"></param>
        /// <returns>网关连接</returns>
        Task<string> GetGateWayUrl(HttpContext context);

        /// <summary>
        /// 获取对象二进制数组
        /// </summary>
        /// <param name="storePath">对象相对路径</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>对象的二进制数组</returns>
        Task<byte[]> GetObjectByteAsync(FilePath storePath, string userName, string groupName);

        /// <summary>
        /// 获取对象流
        /// </summary>
        /// <param name="storePath">对象相对路径</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>对象流</returns>
        Task<Stream> GetObjectStreamAsync(FilePath storePath, string userName, string groupName);

        /// <summary>
        /// 获取文件路径
        /// </summary>
        /// <param name="storePath">对象相对路径</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>对象流</returns>
        Task<Stream> GetObjectStreamAsyncYt(FilePath storePath, string userName, string groupName);

        /// <summary>
        /// 存储文件
        /// </summary>
        /// <param name="objectByte">对象</param>
        /// <param name="objectName">对象名称</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns></returns>
        Task<RespRet<FileIndex>> StoreObjectByteAsync(byte[] objectByte, string objectName, string userName, string groupName);

        /// <summary>
        /// 存储文件
        /// </summary>
        /// <param name="objectStream">文件流</param>
        /// <param name="objectName">对象名称</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>文件路径</returns>
        Task<RespRet<FileIndex>> StoreObjectStreamAsync(Stream objectStream, string objectName, string userName, string groupName);

        /// <summary>
        /// 存储文件
        /// </summary>
        /// <param name="formFile">文件流</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>文件路径</returns>
        Task<RespRet<FileIndex>> StoreFormFileAsync(IFormFile formFile, string userName, string groupName);

        /// <summary>
        /// 存储文件带后缀
        /// </summary>
        /// <param name="formFile">文件流</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns>文件路径</returns>
        Task<RespRet<FileIndex>> StoreFormFileAsyncYt(IFormFile formFile, string userName, string groupName);

        /// <summary>
        /// 文件是否存在
        /// </summary>
        /// <param name="storePath">对象相对路径</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns></returns>
        bool ExistFile(FilePath storePath, string userName, string groupName);


        /// <summary>
        /// 文件是否存在阳台
        /// </summary>
        /// <param name="storePath">对象相对路径</param>
        /// <param name="userName">用户名称</param>
        /// <param name="groupName">分组名称</param>
        /// <returns></returns>
        bool ExistFileYt(FilePath storePath, string userName, string groupName);

        /// <summary>
        /// 存放地址
        /// </summary>
        /// <returns></returns>
        string fileurl();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="storePath"></param>
        /// <param name="userName"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        Task<string> CopyObjectFile(FilePath storePath, string userName, string groupName);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="storePath"></param>
        /// <param name="userName"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        Task<string> CopyObjectFile2FileStore(FilePath storePath, string userName, string groupName);
    }
}
